package com.woniu.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@ApiModel("通用返回类型")
@Data
public class R implements Serializable {
    @ApiModelProperty("响应状态码")
    private Integer code;
    @ApiModelProperty("响应信息提示")
    private String message;
    @ApiModelProperty("响应数据")
    private Map<String,Object> data = new HashMap<>();

    public static R ok(){
        R r = new R();
        r.setCode(200);
        r.setMessage("操作成功");
        return r;
    }

    public static R fail(){
        R r = new R();
        r.setCode(8888);
        r.setMessage("系统异常,请联系管理员！");
        return r;
    }

    public R data(String key, Object value){
        this.data.put(key,value);
        return this;
    }

    public R data(Map<String,Object> map){
        this.setData(map);
        return this;
    }

    public R message(String message){
        this.setMessage(message);
        return this;
    }

    public R code(Integer code){
        this.setCode(code);
        return this;
    }

}
